 /*****************************************************************************
 * func.inc.js                                                                *
 * Last Modified: 2007-06-06                                                  *
 *                                                                            *
 * func.inc.js stores JavaScript functions to be used throughout the          *
 * BBG_Billing application.                                                   *
 *                                                                            *
 * BBG_Billing, a PHP application using MySQL for creating and maintaining a  *
 * contacts and invoices database.                                            *
 *                                                                            *
 * @copyright Copyright (C) 2007, Bugs Bee Gone Computer Services             *
 * @owner     Daniel Barnett (Bugs Bee Gone Computer Services)                *
 * @author    Daniel Barnett <dbarnett@bugsbeegone.com>                       *
 * @website   http://www.bugsbeegone.com                                      *
 * @license   http://www.gnu.org/licenses/gpl.html GNU General Public License *
 * @package   BBG_Billing                                                     *
 * @name      func.inc.js                                                     *
 * @version   1.0.0                                                           *
 *                                                                            *
 * This file is part of the "BBG_Billing" PHP application.                    *
 *                                                                            *
 * BBG_Billing is free software; you can redistribute it and/or modify        *
 * it under the terms of the GNU General Public License as published by       *
 * the Free Software Foundation; either version 2 of the License, or          *
 * (at your option) any later version.                                        *
 *                                                                            *
 * BBG_Billing is distributed in the hope that it will be useful,             *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with BBG_Billing; if not, write to the Free Software                 *
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
 *****************************************************************************/
 
 
 // To use this JavaScript include file...
 //    <script type="text/javascript" src="func.inc.js"></script>


// Check length of a textarea, stop typing when TAMaxLength is met
// Usage Example:
//     <textarea onkeypress="return checkMaxLength(event,this)" TAMaxLength="100"></textarea>
function checkMaxLength(e,el)
{
	switch(e.keyCode) {
		case 37: // left
			return true;
		case 38: // up
			return true;
		case 39: // right
			return true;
		case 40: // down
			return true;
		case 8: // backspace
			return true;
		case 46: // delete
			return true;
		case 27: // escape
			el.value='';
			return true;
		}

	return (el.value.length<el.getAttribute("TAMaxLength"));
}


// Redirect on "Cancel" button click
// Usage Example:
//     <input type="button" onclick="cancel(this)" location="invoices.php" value="Cancel" />
function cancel(element)
{
	var target=element.getAttribute("location");
	window.location=target;
}


// Create a PDF file from the current HTML/PHP document
// Usage Example:
//     function createPDF() {
//         newPDF("http://www.bugsbeegone.com/billing/pdfInvoice.php?invoiceNum=' . $invoiceNum . '", "invoice_' . $invoiceNum . '_' . $date . '");
//     }
function newPDF(filePath, fileName)
{
	var path=filePath;
	var name=fileName;

	window.open('http://www.bugsbeegone.com/billing/include/createPDF.php?filePath=' + path + '&amp;fileName=' + name);
}


// Show/Hide Division (<div>) by ID
function show(sw,obj)
{
	// quick browser tests
	var ns4 = (document.layers) ? true : false;
	var ie4 = (document.all && !document.getElementById) ? true : false;
	var ie5 = (document.all && document.getElementById) ? true : false;
	var ns6 = (!document.all && document.getElementById) ? true : false;

	// show/hide the divisions
	if (sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'visible';
	if (!sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'hidden';
	if (sw && ns4) document.layers[obj].visibility = 'visible';
	if (!sw && ns4) document.layers[obj].visibility = 'hidden';
}


// No Right Click
// Usage Example:
//     <body onload="noRightClick()">
function noRightClick()
{
	// Set the message for the alert box
	am = "Sorry. You do not have permission to right click.";

	// do not edit below this line
	// ===========================
	bV  = parseInt(navigator.appVersion)
	bNS = navigator.appName=="Netscape"
	bIE = navigator.appName=="Microsoft Internet Explorer"

	function nrc(e) {
	   if (bNS && e.which > 1){
	      alert(am)
	      return false
	   } else if (bIE && (event.button >1)) {
	     alert(am)
	     return false;
	   }
	}

	document.onmousedown = nrc;
	if (document.layers) window.captureEvents(Event.MOUSEDOWN);
	if (bNS && bV<5) window.onmousedown = nrc;
}
